package com.proton.carepatchtemp.utils;

import android.util.Log;

import com.proton.carepatchtemp.application.VCare;
import com.proton.carepatchtemp.constant.Settings;
import com.proton.carepatchtemp.utils.net.SignCenter;
import com.umeng.analytics.MobclickAgent;
import com.umeng.message.IUmengRegisterCallback;
import com.umeng.message.PushAgent;


/**
 * Created by Api on 2016/11/3.
 */

public class UmengUtils {


    private static String str = "";

    public static String initUmeng() {
        //友盟统计
        MobclickAgent.openActivityDurationTrack(false);
        //友盟推送
        PushAgent mPushAgent = PushAgent.getInstance(VCare.get());
        if (Settings.isTest) {
            mPushAgent.setDebugMode(true);
        } else {
            mPushAgent.setDebugMode(false);
        }
        //注册推送服务，每次调用register方法都会回调该接口
        mPushAgent.register(new IUmengRegisterCallback() {
            @Override
            public void onSuccess(String deviceToken) {
                //注册成功会返回device token
                Log.e("onSuccess", deviceToken);
                if (VCare.get().isAuthflag()) {
                    SignCenter.setUmtoken(deviceToken);
                    Log.e("onSuccess", "send deviceToken to service succeed");
                }
                str = deviceToken;
            }

            @Override
            public void onFailure(String s, String s1) {
                str = "";
            }
        });
        return str;
    }

    public static String getdeviceToken() {
        return str;
    }
}
